package gybase04

class Person4 {
    def name;
    /*
        重写 propertyMissing 解决 groovy.lang.MissingPropertyException 问题
     */
    //这个相当于对不存在的变量进行get操作
    def propertyMissing(String name){
        println"调用了 propertyMissing"
        if (name == 'age'){
            "22"
        }
//        "20"//这个是返回值，写什么就返回什么

        //最后一行是返回值
    }

    def propertyMissing(String name,def arg){
        println"调用了 propertyMissing 方法带参数 $name , $arg"
       return "propertyMissing 方法带参数"
//        "20"//这个是返回值，写什么就返回什么

        //最后一行是返回值
    }

    def methodMissing(String name,def arg){//方法合成
        println"调用了 methodMissing"
        if (name.startsWith'getFather'){
            "sasa"
        }
    }

}

//new Person4().age//直接报错 groovy.lang.MissingPropertyException: No such property: age for class: gybase04.Person4groovy.lang.MissingPropertyException: No such property: age for class: gybase04.Person4

// 添加属性
println new Person4().age
//调用了 propertyMissing
//22

def per4 = new Person4()
println per4.age = 18
//调用了 propertyMissing 方法带参数 age , 18
//18
println per4.age
//调用了 propertyMissing
//22

println per4.getFather()
//调用了 methodMissing
//sasa


def str = "androidx.appcompat:appcompat:1.2.0"
(group,name,version) = str.split(":")
println "group = $group"
println "name = $name"
println "version = $version"
//group = androidx.appcompat
//name = appcompat
//version = 1.2.0




